Skip to content

fix: emit diagnostic for non-type numeric literal suffix instead of panicking#9810

Open
orizi wants to merge 1 commit intomainfrom
orizi/03-31-fix_non_type_numeric_literal_suffix
Open

fix: emit diagnostic for non-type numeric literal suffix instead of panicking#9810
orizi wants to merge 1 commit intomainfrom
orizi/03-31-fix_non_type_numeric_literal_suffix

Conversation

@orizi
Copy link
Copy Markdown
Collaborator

@orizi orizi commented Mar 31, 2026

Summary

Replace panic with proper error handling when encountering non-type identifiers in numeric literal type suffixes. The try_get_ty_by_name function now returns a SemanticDiagnosticKind::NotAType error instead of panicking when a type suffix is not actually a type.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

The compiler was panicking when encountering numeric literals with non-type suffixes (e.g., 1_boolean where boolean is not a valid type). This caused the compiler to crash instead of providing a proper diagnostic message to the user.


What was the behavior or documentation before?

When a numeric literal had a suffix that wasn't a valid type, the compiler would panic with a message like "boolean is not a type."


What is the behavior or documentation after?

The compiler now gracefully handles this error case by emitting a proper diagnostic error "Not a type." (error code E2011) and continues compilation instead of crashing.


Related issue or discussion (if any)

Fixes #9791


Additional context

The change includes a test case that verifies the new error handling behavior with 1_boolean as an example of a numeric literal with an invalid type suffix.


Note

Medium Risk
Touches core type-resolution helper try_get_ty_by_name, which is used broadly; while the change is limited to an error path, it can alter diagnostics and control flow for invalid code.

Overview
Fixes a compiler crash when resolving numeric literal type suffixes by changing try_get_ty_by_name to return SemanticDiagnosticKind::NotAType instead of panicking when the looked-up item exists but is not a type.

Adds a regression test ensuring 1_boolean produces error E2011 (Not a type) rather than aborting compilation.

Written by Cursor Bugbot for commit 18fe653. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown
Collaborator Author

orizi commented Mar 31, 2026

This stack of pull requests is managed by Graphite. Learn more about stacking.

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eytan-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on orizi and TomerStarkware).


crates/cairo-lang-semantic/src/expr/test_data/literal line 36 at r1 (raw file):


//! > expected_diagnostics
error[E2011]: Not a type.

Bad diagnostic

@orizi orizi changed the base branch from orizi/03-31-fix_macro_rule_missing_param_kind to graphite-base/9810 April 1, 2026 09:05
@orizi orizi force-pushed the graphite-base/9810 branch from dbb21ea to 8dd8779 Compare April 1, 2026 09:17
@orizi orizi force-pushed the orizi/03-31-fix_non_type_numeric_literal_suffix branch from fca4f70 to 3395304 Compare April 1, 2026 09:17
@orizi orizi changed the base branch from graphite-base/9810 to main April 1, 2026 09:17
Copy link
Copy Markdown
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orizi made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on eytan-starkware and TomerStarkware).


crates/cairo-lang-semantic/src/expr/test_data/literal line 36 at r1 (raw file):

Previously, eytan-starkware wrote…

Bad diagnostic

the location isn't very good - but the diagnostic definitely is.

@orizi orizi force-pushed the orizi/03-31-fix_non_type_numeric_literal_suffix branch from 3395304 to 18fe653 Compare April 1, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Compiler panic in corelib: panic! for non-type numeric literal suffix

3 participants